package conf

import (
	"gopkg.in/yaml.v3"
	"io/ioutil"
)

var ConfigInstance *Conf

func InitConf() {
	ConfigInstanceTmp, err := initConf()
	if err != nil {
		panic(err)
	}
	ConfigInstance = ConfigInstanceTmp
}

func initConf() (*Conf, error) {
	confFile := "./conf/grpc_config.yml"
	content, err := ioutil.ReadFile(confFile)
	if err != nil {
		return nil, err
	}
	var conf Conf
	err = yaml.Unmarshal(content, &conf)
	if err != nil {
		return nil, err
	}

	return &conf, nil
}
